package marchsoft.modules.four.admin.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import marchsoft.base.BasicServiceImpl;
import marchsoft.base.PageVO;
import marchsoft.modules.four.admin.entity.dto.SafeCaseDTO;
import marchsoft.modules.four.admin.mapper.SafeTypeMapper;
import marchsoft.modules.four.admin.service.SafeCaseService;
import marchsoft.modules.four.common.entity.SafeCase;
import marchsoft.modules.four.common.entity.SafeType;
import marchsoft.modules.four.common.mapper.MapperSafeCase;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@RequiredArgsConstructor
public class SafeCaseServiceImpl extends BasicServiceImpl<MapperSafeCase, SafeCase> implements SafeCaseService {
    private final SafeTypeMapper safeTypeMapper;


    @Override //分页条件查询安全案例
    public IPage<SafeCase> queryAll1(PageVO pageVO, SafeCaseDTO safeCaseDTO) {
        IPage<SafeCase> page = new Page<>(pageVO.getCurrent(), pageVO.getSize());
        QueryWrapper<SafeCase> queryWrapper = new QueryWrapper<>();
        Long safeTypeID = safeCaseDTO.getSafeTypeId();
        if (safeTypeID != null){
            queryWrapper.eq("safe_type", safeTypeID);
        }
        String keyWords = safeCaseDTO.getKeywords();
        if (keyWords != null){
            queryWrapper.eq("keywords",keyWords);
        }
        queryWrapper.orderByDesc("create_time");
        return page(page, queryWrapper);
    }

    @Override //查询所有安全分类名称
    public List<SafeType> selectAllNameSafeType() {
        return safeTypeMapper.selectAllSafeTypeName();
    }

    @Override //新增安全案例
    public void insertSafeCase(SafeCase safeCase) {
        save(safeCase);
    }

    @Override //更新安全案例
    public void updateSafeCase(SafeCase safeCase) {
        updateById(safeCase);
    }

    @Override //根据id删除安全案例
    public void deleteSafeCase(List<Integer> id) {
        removeByIds(id);
    }
}
